@isTest
private class PartRequirePlanControllerTest {
    static testMethod void testMethod1() {
        
          // 产品
        Product__c p = TestUtils.createProduct();
        p.ProductName__c = '测试产品';
        p.NCCode__c = '1300001';
        p.Company__c = '四川省迈克实业有限公司';
       	insert p ; 

        EngineeringPartsRequirementPlanning__c  erpp = new EngineeringPartsRequirementPlanning__c();
        erpp.Company__c= 'MKSY';
        erpp.DemandOrganization__c = 'MKSY';
        erpp.DemandWarehouse__c = '迈克配件库';
        insert erpp; 

        EngineeringPartsRequirementDetails__c erpd = new EngineeringPartsRequirementDetails__c();
        erpd.EngineeringPartsRequirementPlanning__c = erpp.Id ; 
        erpd.OrderAmount__c = 10 ; 
        erpd.Product__c = p.Id; 

        insert erpd ; 

        PageReference page = new PageReference('/apex/PartRequirePlan?id=' + erpp.Id );
        System.Test.setCurrentPage(page);
        PartRequirePlanController prpc =new  PartRequirePlanController();

        prpc.init();

        Map<String,String> searchMap = new Map<String,String>();
        searchMap.put('ProductName__c', '测试产品');
        prpc.searchJson = EncodingUtil.urlEncode(JSON.serialize(searchMap), 'UTF-8');
        prpc.search();

        List<PartRequirePlanController.EPRDBean> elist = new List<PartRequirePlanController.EPRDBean>();

        PartRequirePlanController.EPRDBean eprdb = new PartRequirePlanController.EPRDBean(erpd);
        elist.add(eprdb );

        prpc.saveJson =  EncodingUtil.urlEncode(JSON.serialize(elist), 'UTF-8');

        prpc.save(); 

        PartRequirePlanController.matchProduct(new List<String>{'1300001'},'四川省迈克实业有限公司');


        erpp.Status__c= '审批成功';
        update erpp; 
        StockDetailsWebservice.postRequireBuy(erpp.Id );



    }
}